<?php

use Yaf\Registry;


class AlibabaTestController extends ApiBaseController
{
    /**
     * 获取我的选品库列表
     * @return bool
     */
    public function listCybUserGroupAction() {

        $arr = [
            'errorCode' => '000',
            'errorMsg' => '',
            'success' => true,
            'totalRow' => 100,
            'result' => [
                [
                    'createTime' => date("YmdHis", time()),
                    'feedCount' => 2,
                    'id' => 1,
                    'title' => '选品库1'
                ],
                [
                    'createTime' => date("YmdHis", time()),
                    'feedCount' => 10,
                    'id' => 2,
                    'title' => '选品库2'
                ]
            ]
        ];

        return $this->getResponse()->setBody(json_encode($arr));
    }

    /**
     * 获取选品库已选商品列表
     * @return bool
     */
    public function listCybUserGroupFeedAction() {
        $parameters = Registry::get('parameters');
        $arr = [
            'errorCode' => '000',
            'errorMsg' => '',
            'success' => "true",
            'totalRow' => 2,
            'resultList' => [
                [
                    'createTime' => date("YmdHis", time()),
                    'feedId' => '584051070147',
                    'price' => '1.1',
                    'title' => '商品标题1',
                    'promotionPrice' => '0.9',
                    'promotionSpace' => '-',
                    'invalid' => "true",
                    'invalidInfo' => '',
                    'imgUrl' => 'http://img.com',
                    'saleCount' => '333',
                    'channelPrice' => '11.22'
                ],
                [
                    'createTime' => date("YmdHis", time()),
                    'feedId' => '12',
                    'price' => '2.2',
                    'title' => '商品标题2',
                    'promotionPrice' => '1.8',
                    'promotionSpace' => '-',
                    'invalid' => "false",
                    'invalidInfo' => '下架了',
                    'imgUrl' => 'http://img.com',
                    'saleCount' => '222',
                    'channelPrice' => '33.22'
                ]
            ]
        ];
        return $this->getResponse()->setBody(json_encode($arr));
    }

    /**
     * 获取商品详情接口
     * @return bool
     */
    public function productInfoAction() {
        /*$arr = [
            'errorCode' => '000',
            'errorMsg' => '',
            'success' => true,
            'totalRow' => 1,
            'productInfo' => [
                'productID' => '584051070147',
                'categoryID' => '1048182',
                'groupID' => ['107331682'],
                'subject' => '高端气质OL韩版雪纺女装套头半高领长袖修身型蕾丝衫',
                'description' => '高端气质OL韩版雪纺女装套头半高领长袖修身型蕾丝衫',
                'pictureAuth' => 'false',
                'images' => [
                    "img/ibank/2014/766/624/1652426667_642119312.jpg",
                    "img/ibank/2014/656/624/1652426656_642119312.jpg",
                    "img/ibank/2014/236/624/1652426632_642119312.jpg"
                ],
                'skuInfos' => [
                    [
                        'attributes' => [
                            [
                                'attributeID' => '3216',
                                'attributeValue' => '白色',
                                'skuImageUrl' => 'img/ibank/2018/852/384/9326483258_1660977857.jpg',
                                'attributeDisplayName' => '颜色',
                                'attributeName' => '颜色'
                            ],
                            [
                                'attributeID' => '3201',
                                'attributeValue' => 'm',
                                'skuImageUrl' => 'img/ibank/2018/852/384/9326483258_1660977857.jpg',
                                'attributeDisplayName' => '尺码',
                                'attributeName' => '尺码'
                            ]
                        ],
                        'cargoNumber' => '666',
                        'amountOnSale' => '1490',
                        'retailPrice' => '445',
                        'price' => '445',
                        'skuId' => '3935963888523',
                        'sepcId' => 'b265340beb52182c6bcfbff1fad02f0b',
                        'consignPrice' => '445',
                        'cpsSuggestPrice' => '555',
                        'channelPrice' => '553',
                    ],
                    [
                        'attributes' => [
                            [
                                'attributeID' => '3217',
                                'attributeValue' => '黑色',
                                'skuImageUrl' => 'img/ibank/2018/852/384/9326483258_1660977857.jpg',
                                'attributeDisplayName' => '颜色',
                                'attributeName' => '颜色'
                            ],
                            [
                                'attributeID' => '3201',
                                'attributeValue' => 'm',
                                'skuImageUrl' => 'img/ibank/2018/852/384/9326483258_1660977857.jpg',
                                'attributeDisplayName' => '尺码',
                                'attributeName' => '尺码'
                            ]
                        ],
                        'cargoNumber' => '667',
                        'amountOnSale' => '123',
                        'retailPrice' => '445',
                        'price' => '445',
                        'skuId' => '3935963888524',
                        'sepcId' => 'b265340beb52182c6bcfbff1fad02f0a',
                        'consignPrice' => '445',
                        'cpsSuggestPrice' => '555',
                        'channelPrice' => '553',
                    ]
                ],
                'saleInfo' => [
                    'supportOnlineTrade' => true,
                    'mixWholeSale' => true,
                    'priceAuth' => true,
                    'priceRanges' => [
                        'startQuantity' => 3,
                        'price' => 445
                    ],
                    'amountOnSale' => '29900',
                    'unit' => '件',
                    'minOrderQuantity' => 3,
                    'batchNumber' => '12',
                    'retailprice' => '445',
                    'sellunit' => '手'
                ],
                'imgUrl' => 'http://img.com',
                'saleCount' => '333',
                'channelPrice' => '11.22',
                'status' => 'approved'
            ],
            'bizGroupInfos' => [
                'support' => true,
                'description' => '',
                'code' => ''
            ],
            'attributes' => [
                [
                    'attributeID' => '3216',
                    'attributeName' => '颜色',
                    'valueID' => '3216',
                    'value' => '白色',
                    'isCustom' => 'false',
                ],
                [
                    'attributeID' => '3201',
                    'attributeName' => '尺寸',
                    'valueID' => '3201',
                    'value' => 'm',
                    'isCustom' => 'false',
                ],
                [
                    'attributeID' => '3217',
                    'attributeName' => '颜色',
                    'valueID' => '3217',
                    'value' => '黑色',
                    'isCustom' => 'false',
                ]
            ]
        ];*/
        $arr = json_decode('{
  
  "bizGroupInfos":  [
    {
    
      "code":  "isConsignMarketOffer",
    
      "description":  "1688代销产品",
    
      "support":  false
    
  }
  ],
  
  "productInfo":  {
    
    "categoryID":  1031910,
    
    "categoryName":  "连衣裙",
    
    "description":  "abc",
    
    "image":  {
      
      "images":  [
      "https: //cbu01.alicdn.com/img/ibank/2018/868/892/9555298868_511594667.jpg"
      ]
    
    },
    
    "pictureAuth":  false,
    
    "productID":  584051070147,
    
    "status": "approved",
    
    "referencePrice":  "10.0",
    
    "saleInfo":  {
      
      "amountOnSale":  1999853.0,
      
      "minOrderQuantity":  2,
      
      "mixWholeSale":  false,
      
      "priceAuth":  false,
      
      "priceRanges":  [
        {
        
          "price":  10.0,
        
          "startQuantity":  2
        
      }
      ],
      
      "quoteType":  1,
      
      "supportOnlineTrade":  true,
      
      "unit":  "件"
    
    },
    
    "shippingInfo":  {
      
      "freightTemplateID":  1,
      
      "sendGoodsAddressId":  14346579,
      
      "sendGoodsAddressText":  "青海省 果洛藏族自治州"
    
    },
    
    "skuInfos":  [
      {
      
        "amountOnSale":  999931,
      
        "attributes":  [
          {
        
            "attributeID":  3216,
        
            "attributeName":  "颜色",
        
            "attributeValue":  "黄色",
        
            "skuImageUrl":  "https: //cbu01.alicdn.com/img/ibank/2018/308/983/9359389803_511594667.jpg"
          
      },
      
          {
        
            "attributeID":  450,
        
            "attributeName":  "尺码",
        
            "attributeValue":  "XS"
          
      }
        ],
      
        "cargoNumber":  "",
      
        "consignPrice":  10.0,
      
        "price":  10.0,
      
        "skuId":  4127294243178,
      
        "specId":  "af478130f6c683c4c77bb511796617d7"
      
    }
    ],
    
    "subject":  "大市场的offer"
  
  },
  
  "success":  true

}', true);
        return $this->getResponse()->setBody(json_encode($arr));
    }

    /**
     * 获取营销活动价格等活动信息
     * @return bool
     */
    public function queryOfferDetailActivityAction() {
        $arr = [
            'errorCode' => '000',
            'errorMsg' => '',
            'success' => "true",
            'totalRow' => 2,
            'result' => [
                'offerId' => '584051070147',
                'activityId' => '11',
                'activityName' => '活动名称',
                // 预热时间,活动未开始,不可用活动价下单; 为null表示无预热时间
                'hotTime' => '20200210000000000+0800',
                // 活动开始时间；大于now时，活动有效
                'startTime' => '20200310000000000+0800',
                // 活动结束时间；小于now时，活动有效
                'endTime' => '20200410000000000+0800',
                // 活动起批量
                'beginQuantity' => '2',
                // 活动总库存，为null时使用offer原库存
                'stock' => '3',
                // 商品本身限购数，非活动价可购买数；-1表示不限，0表示可购买数为0；3个*LimitCount字段都等于-1时，表示没有任何限购
                'personLimitCount' => '-1',
                // 限购数，等于0且personLimitCount>0时，可以以原价下单，但不能以活动价下单；-1表示不限数量；3个*LimitCount字段都等于-1时，表示没有任何限购
                'promotionLimitCount' => '-1',
                // 活动限购数；该场内活动商品限购数，-1表示不限购；0表示不可购买该场活动所有商品；3个*LimitCount字段都等于-1时，表示没有任何限购
                'activityLimitCount' => '-1',
                // 活动限时包邮开始时间；null 表示不限时
                'freepostageStartTime' => '20200310000000000+0800',
                // 活动限时包邮结束时间；null 表示不限时
                'freepostageEndTime' => '20200325000000000+0800',
                // 免包邮地区，与活动包邮配合使用
                'excludeAreaList' => [
                    [
                        'code' => '0000',
                        'name' => '地区'
                    ]
                ],
                // 如果offer是范围报价，且价格优惠是折扣的情况，返回折扣计算后的价格范围;优先取该字段，该字段为空时，表示分sku报价，取promotionItemList
                'rangePrice' => [
                    [
                        // 区间价数组，每个item为一个价格,以分为单位
                        'price' => [3,2,1],
                        // 区间对应的起批量
                        'beginQuantity' => [3,6,9]
                    ]
                ],
                // 优惠结果，根据优惠方式（PromotionInfo），结合offer的原价信息，计算出优惠结果：每个sku或者每个区间价的促销价，折扣率
                'promotionItemList' => [
                    [
                        // sku优惠结果时有意义；对于区间价的优惠结果，此字段无意义，可能为null
                        'skuId' => '4127294243178',
                        // 原价，单位分
                        'originalPrice' => 10.0,
                        // 优惠价，单位分
                        'promotionPrice' => 5.0
                    ]
                ],
                // sku维度的库存结果
                'skuStockList' => [
                    [
                        // 库存
                        'stock' => 1,
                        'skuId' => '4127294243178',
                    ]
                ],
                // 这里平台会计算一个推荐使用的下单flow，可以用这个flow值调用下单接口
                'introOrderFlow' => 'general'

            ]
        ];
        return $this->getResponse()->setBody(json_encode($arr));

    }

    /**
     * 关注商品
     * @return bool
     */
    public function followAction() {
        Registry::get('alibaba_log')->debug(json_encode([
            $this->getRequest()->getMethod(),
            $this->getRequest()->getRequestUri(),
            Registry::get('parameters')
        ]));

        $arr = [
            'code' => 0,
            'message' => 'failure'
        ];
        return $this->getResponse()->setBody(json_encode($arr));
    }

    /**
     * 模拟1688服务器，往指定接口发送商品状态变化的通知消息
     * @throws Exception
     */
    public function productStatusAction() {
        $parameters = Registry::get('parameters');
        $msg = [
            'productIds' => '584051070147',
            'memberId' => '123',
            'msgSendTime' => date('Y-m-d H:i:s', time())
        ];

        switch ($parameters['action']) {
            // 1688产品删除（关系用户视角）
            case 'PRODUCT_RELATION_VIEW_PRODUCT_DELETE':
                $msg['status'] = 'RELATION_VIEW_PRODUCT_DELETE';
                break;
            // 1688产品下架（关系用户视角）
            case 'PRODUCT_RELATION_VIEW_PRODUCT_EXPIRE':
                $msg['status'] = 'RELATION_VIEW_PRODUCT_EXPIRE';
                break;
            // 1688产品新增或修改（关系用户视角）
            case 'PRODUCT_RELATION_VIEW_PRODUCT_NEW_OR_MODIFY':
                $msg['status'] = 'RELATION_VIEW_PRODUCT_NEW_OR_MODIFY';
                break;
            // 1688产品上架（关系用户视角）
            case 'PRODUCT_RELATION_VIEW_PRODUCT_REPOST':
                $msg['status'] = 'RELATION_VIEW_PRODUCT_REPOST';
                break;
            // 1688产品审核下架（关系用户视角）
            case 'PRODUCT_RELATION_VIEW_PRODUCT_AUDIT':
                $msg['status'] = 'RELATION_VIEW_PRODUCT_AUDIT';
                break;
            // 	1688商品库存变更消息
            case 'PRODUCT_PRODUCT_INVENTORY_CHANGE':
                $msg = [
                    'OfferInventoryChangeList' => [
                        // 1688商品id
                        'offerId' => '584051070147',
                        // 在线可售offer数量
                        'offerOnSale' => 100,
                        // 商品skuId
                        'skuId' => 4127294243179,
                        // 在线可售sku数量
                        'skuOnSale' => 20,
                        // 该offer整体库存变化数
                        'quantity' => -10,
                        'bizTime' => time()
                    ]
                ];
                break;
            // 商品池&超买价变更消息
            case 'PRODUCT_RELATION_VIEW_EXIT_SUPERBUYER':
                $msg = [
                    'products' => [
                        // 商品id
                        'productId' => '584051070147',
                        // 是否支持超买价;true支持超买价
                        'supportSuperPrice' => true,
                        // 商品状态;枚举,
                        // DELETE:删除商品,商品不在商品池;
                        // UPDATE:商品超买价状态可能有更新;
                        // 机构可以只关心DELETE状态判断是否在商品池
                        'status' => 'DELETE'
                    ]
                ];
                break;
            default:
                break;
        }

        if (! isset($msg['status']) && isset($msg['productIds']))
            throw new Exception('无效请求');

        $url = 'http://www.ylmall.com/notify/alibaba/productNotify';
        $header = [
            'Content-Type: application/x-www-form-urlencoded'
        ];
        list($header_size, $body) = \youliPhpLib\Common\RequestHelper::curlRequest(
            $url,
            http_build_query(['message' => json_encode($msg), '_aop_signature' => '123']),
            'POST', $header);

        var_dump(substr($body, $header_size));
        exit();
//        return $this->getResponse()->setBody(json_encode($msg));
    }

    /**
     * 模拟1688接口，往指定接口发送商品状态变化的通知消息
     * @throws Exception
     */
    public function orderStatusAction() {
        $parameters = Registry::get('parameters');
        $msg = [
            'orderId' => '1688-orderId-1588584138',
            'msgSendTime' => date('Y-m-d H:i:s', time()),
            // 买家中文站会员ID
            'buyerMemberId' => '',
            // 卖家中文站会员ID
            'sellerMemberId' => ''
        ];

        switch ($parameters['action']) {
            // 1688订单部分发货（买家视角）/Partial delivery of 1688 order (buyer view)
            case 'ORDER_BUYER_VIEW_PART_PART_SENDGOODS':
                $msg['currentStatus'] = 'waitsellersend';
                break;
            // 	1688订单发货（买家视角）/1688 order delivery (buyer view)
            case 'ORDER_BUYER_VIEW_ANNOUNCE_SENDGOODS':
                $msg['currentStatus'] = 'waitbuyerreceive';
                break;
            // 1688订单确认收货（买家视角）/order receipt confirmation (buyer view)
            case 'ORDER_BUYER_VIEW_ORDER_COMFIRM_RECEIVEGOODS':
                $msg['currentStatus'] = 'confirm_goods_and_has_subsidy';
                break;
            // 1688交易成功（买家视角）
            case 'ORDER_BUYER_VIEW_ORDER_SUCCESS':
                $msg['currentStatus'] = 'success';
                break;
            // 1688买家关闭订单（买家视角）/buyer closing order (buyer view)
            case 'ORDER_BUYER_VIEW_ORDER_BUYER_CLOSE':
                $msg['currentStatus'] = 'cancel';
                break;
            // 	1688订单售中退款（买家视角）
            case 'ORDER_BUYER_VIEW_ORDER_BUYER_REFUND_IN_SALES':
                // 当前订单状态
                $msg['currentStatus'] = '';
                // 退款操作, 具体状态:
                // SELLER_SEND_GOODS_CLOSE(卖家发货关闭)、
                // SELLER_UPLOAD_BILL(卖家上传凭证)、
                // SELLER_REJECT_REFUND(卖家拒绝退款)、
                // SELLER_AGREE_REFUND(卖家同意退款)、
                // SELLER_RECEIVE_GOODS(卖家确认收货)、
                // SELLER_APPLY_SUPPORT(卖家申请客服介入)、
                // SELLER_CONFIRM_ORDER_CLOSE(卖家确认，退款关闭，分阶段订单情况)、
                // SELLER_STEP_PUSH_CLOSE(卖家推进，退款关闭，分阶段订单情况)、
                // SYSTEM_AGREE_REFUND_PROTOCOL(系统超时同意退款协议)、
                // SYSTEM_AGREE_REFUND(系统超时同意退款，即退款成功)、
                // SYSTEM_SEND_GOODS(系统超时退货，主交易流程的退货)、
                // SYSTEM_MODIFY_REFUND_PROTOCOL(系统超时修改协议)、
                // SYSTEM_NOTIFY_APPLY_SUPPORT(系统通知申请客服介入)、
                // SELLER_AGREE_REFUND_PROCOTOL(卖家同意退款协议)、
                // SELLER_REJECT_REFUND_PROCOTOL(卖家拒绝退款协议)、
                // CRM_APPLY_TIMEOUT_CLOSE(申请客服介入、超时关闭、目前仅售后业务在用)、
                // CRM_APPLY_SUPPORT(CRM申请介入)、
                // CRM_INTERVENE_TASK(CRM介入处理)、
                // CRM_DISMISS_TASK(CRM撤销工单)、
                // CRM_FINISH_TASK(CRM完结工单)、
                // BUYER_APPLY_REFUND(买家申请退款)、
                // BUYER_RECEIVE_CLOSE(买家确认收货关闭)、
                // BUYER_CANCEL_REFUND_CLOSE(买家撤销退款申请关闭)、
                // BUYER_UPLOAD_BILL(买家上传凭证)、
                // BUYER_SEND_GOODS(买家声明发货)、
                // BUYER_MODIFY_REFUND_PROTOCOL(买家修改退款协议)、
                // BUYER_APPLY_SUPPORT(买家申请客服介入)、
                // BUYER_STEP_PAY_ORDER_CLOSE(买家支付，退款关闭，分阶段订单情况)、
                // BUYER_STEP_CONFIRM_CLOSE(买家确认，退款关闭，分阶段订单情况)、
                // BUYER_CLOSE_TRADE_CLOSE(买家终止交易，退款关闭，分阶段订单情况)、
                $msg['currentStatus'] = '';
                $msg['refundAction'] = 'SELLER_AGREE_REFUND';
                // 操作的发起人
                $msg['operator'] = 'seller';
                // 退款单ID
                $msg['refundId'] = '123321';
                break;
            // 1688订单售后退款（买家视角）
            case 'ORDER_BUYER_VIEW_ORDER_REFUND_AFTER_SALES':
                // 当前订单状态
                $msg['currentStatus'] = '';
                $msg['refundAction'] = 'SELLER_AGREE_REFUND_PROCOTOL';
                // 操作的发起人
                $msg['operator'] = 'seller';
                // 退款单ID
                $msg['refundId'] = '123321';
                break;
            // 1688订单售中退货 等待买家发货
            case 'BUYER_SEND_GOODS':
                // 当前订单状态
                $msg['currentStatus'] = '';
                $msg['refundAction'] = 'BUYER_SEND_GOODS';
                // 操作的发起人
                $msg['operator'] = 'buyer';
                // 退款单ID
                $msg['refundId'] = '123321';
                break;
            // 1688订单售中退货 等待卖家收货
            case 'SELLER_RECEIVE_GOODS':
                // 当前订单状态
                $msg['currentStatus'] = '';
                $msg['refundAction'] = 'SELLER_RECEIVE_GOODS';
                // 操作的发起人
                $msg['operator'] = 'seller';
                // 退款单ID
                $msg['refundId'] = '123321';
                break;
            // 1688订单售中年卖家拒绝退货、退款
            case 'SELLER_REJECT_REFUND':
                // 当前订单状态
                $msg['currentStatus'] = '';
                $msg['refundAction'] = 'SELLER_REJECT_REFUND';
                // 操作的发起人
                $msg['operator'] = 'seller';
                // 退款单ID
                $msg['refundId'] = '123321';
                break;
            default:
                break;
        }

        if (! isset($msg['currentStatus']))
            throw new Exception('无效请求');

        $url = 'http://www.ylmall.com/notify/alibaba/orderNotify';
        $header = [
            'Content-Type: application/x-www-form-urlencoded'
        ];
        list($header_size, $body) = \youliPhpLib\Common\RequestHelper::curlRequest(
            $url,
            http_build_query(['message' => json_encode($msg), '_aop_signature' => '123']),
            'POST', $header);

        var_dump(substr($body, $header_size));
    }

    /**
     * 模拟1688根据地址信息解析地区码接口
     * @return bool
     */
    public function orderTradeAddressCodeParseAction() {
        $parameters = Registry::get('parameters');
        $json_str = '{
            "result":  {
                "address":  "网商路699号",
                "addressCode":  "330108",
                "isDefault":  false,
                "latest":  false,
                "postCode":  "310051"
            },
            "errorCode": "0",
            "errorMessage": "123"
        }';
        $arr = json_decode($json_str, true);
        return $this->_responseString(json_encode($arr));
    }

    /**
     * 模拟1688的创建溢价订单预览接口
     * @return bool
     */
    public function orderCreateOrderPreview4CybMediaAction() {
        $parameters = Registry::get('parameters');
        $json_str = '{
            "orderPreviewResuslt": [{
                "tradeModeNameList": ["nzassure"],
                "status": true,
                "taoSampleSinglePromotion": false,
                "sumPayment": 4400,
                "sumCarriage": 800,
                "sumPaymentNoCarriage": 3600,
                "flowFlag": "general",
                "cargoList": [{
                    "amount": 36,
                    "finalUnitPrice": 18,
                    "specId": "584051070147",
                    "skuId": 4127294243179,
                    "offerId": "af478130f6c683c4c77bb511796617b8",
                    "cargoPromotionList": []
                }],
                "shopPromotionList": [],
                "tradeModelList": [{
                    "tradeType": "nzassure",
                    "name": "担保交易",
                    "description": "买家下单5天内全款支付。自卖家发货起，买家需在10天内确认收货，确认收货后打款给卖家。特别提醒：如卖家已开通极速到账服务，将优先适用极速到账交易，买家支付款项将直接打入卖家账户，详见《极速到账交易及争议处理规则》。",
                    "opSupport": true
                }]
            }],
            "success": true,
            "errorCode": "0",
            "errorCode": "500_007",
            "errorMsg": "与供应商的代销关系不存在,不能使用saleproxy通道下单。",
            "postFeeByDescOfferList": [12324324234,12312422],
            "consignOfferList": [12324324234,12312422]
        }';
        $arr = json_decode($json_str, true);
        return $this->_responseString(json_encode($arr));
    }

    /**
     * 模拟1688的创建溢价订单接口
     * @return bool
     */
    public function tradeCreateOrder4CybMediaAction() {
        $arr = [
            'errorCode' => '400',
            'errorMsg' => 'TOKEN失效，需要重新获取',
            'success' => true,
            'result' => [
                // 下单成功的订单总金额，单位：分
                'totalSuccessAmount' => 720,
                // 下单成功后的订单id
                'orderId' => '1688-orderId-' . time(),
                // 原始运费，单位：分。注意：下单后卖家可能调整，因此该值可能不等于最终支付运费
                'postFee' => 100,
            ]
        ];
        return $this->_responseString(json_encode($arr));
    }

    /**
     * 模拟1688的支付宝协议支付接口
     * @return bool
     */
    public function tradePayProtocolPayAction() {
        $arr = [
            'errorCode' => '4001',
            'errorMsg' => '请求参数为空',
            'success' => true
        ];
        return $this->_responseString(json_encode($arr));
    }

    /**
     * 模拟1688的查询退款退货原因（用于创建退款退货）接口
     * @return bool
     */
    public function tradeRefundReasonListAction() {
        $need_voucher = $_POST['goodsStatus'] == 'refundWaitSellerSend' ? true : false;
        $no_refund_carriage = false;
        $arr = [
            'code' => '0',
            'message' => '0',
            'success' => true,
            'result' => [
                'reasons' => [
                    [
                        'id' => 1,
                        'name' => '退款或退货的原因1',
                        'needVoucher' => $need_voucher,
                        'noRefundCarriage' => $no_refund_carriage
                    ],
                    [
                        'id' => 2,
                        'name' => '退款或退货的原因2',
                        'needVoucher' => $need_voucher,
                        'noRefundCarriage' => $no_refund_carriage
                    ],
                ]
            ],
        ];
        return $this->_responseString(json_encode($arr));
    }

    /**
     * 模拟1688的创建退款退货申请接口
     * @return bool
     */
    public function tradeCreateRefundAction() {
        $order_id = $_POST['orderId'];
        $arr = [
            'code' => '5001',
            'message' => '订单不存在',
            'success' => true,
            'result' => [
                'refundId' => 'TQ' . $order_id
            ],
        ];
        return $this->_responseString(json_encode($arr));
    }

    /**
     * 模拟1688的物流公司列表-所有的物流公司接口
     * @return bool
     */
    public function logisticsOpQueryLogisticCompanyListAction() {
        $arr = [
            'errorCode' => '0',
            'errorMessage' => '',
            'extErrorMessage' => '',
            'success' => true,
            'result' => [
                [
                    'id' => 1,
                    'companyName' => '顺丰快递',
                    'companyNo' => 111,
                    'companyPhone' => '400-800-1234',
                    'supportPrint' => true,
                    'spelling' => 'shufengkuaidi'
                ],
                [
                    'id' => 2,
                    'companyName' => '圆通快递',
                    'companyNo' => 222,
                    'companyPhone' => '400-800-5678',
                    'supportPrint' => true,
                    'spelling' => 'yuantongkuaidi'
                ]
            ],
        ];
        return $this->_responseString(json_encode($arr));
    }

    /**
     * 模拟1688的物流公司列表-自联物流
     * @return bool
     */
    public function logisticsOpQueryLogisticCompanyListOfflineAction() {
        $arr = [
            'errorCode' => '0',
            'errorMessage' => '',
            'extErrorMessage' => '',
            'success' => true,
            'result' => [
                [
                    'id' => 1,
                    'companyName' => '顺丰快递',
                    'companyNo' => 111,
                    'companyPhone' => '400-800-1234',
                    'supportPrint' => true,
                    'spelling' => 'shufengkuaidi'
                ],
                [
                    'id' => 2,
                    'companyName' => '圆通快递',
                    'companyNo' => 222,
                    'companyPhone' => '400-800-5678',
                    'supportPrint' => true,
                    'spelling' => 'yuantongkuaidi'
                ]
            ],
        ];
        return $this->_responseString(json_encode($arr));
    }

    /**
     * 模拟1688的上传退款退货凭证接口
     * @return bool
     */
    public function tradeUploadRefundVoucherAction() {
        $arr = [
            'result' => [
                'code' => '4000',
                'message' => '网络延迟、内部服务异常',
                'success' => true,
                'result' => [
                    'imageDomain' => 'https://www.1688.com/',
                    'imageRelativeUrl' => $_FILES['imageData']['name']
                ]
            ]
        ];
        return $this->_responseString(json_encode($arr));
    }

    /**
     * 模拟1688的上传退货快递单号接口
     * @return bool
     */
    public function tradeRefundReturnGoodsAction() {
        $arr = [
            'result' => [
                'success' => true,
                'errorCode' => '4002',
                'errorInfo' => '物流公司编号和运单号必填'
            ]
        ];
        return $this->_responseString(json_encode($arr));
    }
}
